import axios from 'axios'
import {
  Message
} from 'element-ui'
import util from '@/libs/util'
export const baseURL = 'https://zp.546899.top'
//export const baseURL = 'http://127.0.0.1:8000'
const service = axios.create({
  baseURL,
  timeout: 5000,
  withCredentials: true
})
service.interceptors.request.use(
  config => {
    const token = util.cookies.get('token')
    if (token) {
      config.headers.Authorization = `Bearer ${token}`
    }
    config.headers['Content-Type'] = 'application/json;charset=UTF-8'
    return config
  },
  error => {
    return Promise.reject(error)
  }
)
service.interceptors.response.use(
  response => {
    return response
  },
  error => {
    return Promise.reject(error)
  }
)
export function get(url, params) {
  return service({
    url,
    method: 'get',
    params
  })
}
export function post(url, data) {
  return service({
    url,
    method: 'post',
    data
  })
}
export function put(url, data) {
  return service({
    url,
    method: 'put',
    data
  })
}
export function del(url, data) {
  return service({
    url,
    method: 'delete',
    data
  })
}
export function patch(url, data) {
  return service({
    url,
    method: 'patch',
    data
  })
}
